package result

type ResCode int

const (
	CodeSuccess        ResCode = 100200 + iota // 成功 100200
	CodeInsertSuccess                          // 记录插入成功 100201
	CodeUpdateSuccess                          // 记录更新成功  100202
	CodeDeleteSuccess                          // 记录删除成功  100203
	CodeOperateSuccess                         // 记录操作成功  100204
)

const (
	CodeError         ResCode = 100001 + iota // 失败 100001
	CodeInvalidParam                          // 参数验证失败
	CodeNeedLogin                             // 需要登录
	CodeInvalidToken                          // Token无效
	CodeMissToken                             // Token信息丢失
	CodeInvalidOpenid                         // 无效的openid
	CodeOrderExits                            // 订单已存在
)

const (
	CodeNoMethod  ResCode = 100400 // 错误的请求 100400
	CodeForbidden ResCode = 100403 // 错误的请求 100403
	CodeNoRoute   ResCode = 100404 // 错误的请求 100404
)

const (
	CodeInternalServerError ResCode = 100500 + iota // 服务器内部错误 100500
)

var codeMsgMap = map[ResCode]string{
	CodeSuccess:        "success",
	CodeInsertSuccess:  "新增成功",
	CodeUpdateSuccess:  "更新成功",
	CodeDeleteSuccess:  "删除成功",
	CodeOperateSuccess: "操作成功",

	// -------------------------------//
	CodeError:        "failed",
	CodeInvalidParam: "无效的参数",
	CodeNeedLogin:    "需要登录",
	CodeInvalidToken: "无效的Token",
	CodeMissToken:    "Token信息丢失",

	//---------------------------------//
	CodeNoMethod:  "请求方法不存在",
	CodeNoRoute:   "请求路径错误",
	CodeForbidden: "forbidden",

	// -------------------------------//
	CodeInternalServerError: "服务器内部错误",
}

func (c ResCode) Msg() string {
	if msg, ok := codeMsgMap[c]; ok {
		return msg
	}
	return codeMsgMap[CodeError]
}
